package b.l.a;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.Fragment.b;
import b.f.h;
import c.b.a.a.a;
import java.lang.reflect.InvocationTargetException;

/* compiled from: FragmentFactory */
public class f {
    public static final h<String, Class<?>> a = new h();

    public static Class<?> b(ClassLoader classLoader, String str) throws ClassNotFoundException {
        h hVar = a;
        Class<?> cls = (Class) hVar.getOrDefault(str, null);
        if (cls != null) {
            return cls;
        }
        Class cls2 = Class.forName(str, false, classLoader);
        hVar.put(str, cls2);
        return cls2;
    }

    public static Class<? extends Fragment> c(ClassLoader classLoader, String str) {
        String str2 = "Unable to instantiate fragment ";
        try {
            return b(classLoader, str);
        } catch (ClassNotFoundException e) {
            throw new b(a.E(str2, str, ": make sure class name exists"), e);
        } catch (ClassCastException e2) {
            throw new b(a.E(str2, str, ": make sure class is a valid subclass of Fragment"), e2);
        }
    }

    public Fragment a(ClassLoader classLoader, String str) {
        String str2 = ": make sure class name exists, is public, and has an empty constructor that is public";
        String str3 = "Unable to instantiate fragment ";
        try {
            return (Fragment) c(classLoader, str).getConstructor(new Class[0]).newInstance(new Object[0]);
        } catch (InstantiationException e) {
            throw new b(a.E(str3, str, str2), e);
        } catch (IllegalAccessException e2) {
            throw new b(a.E(str3, str, str2), e2);
        } catch (NoSuchMethodException e3) {
            throw new b(a.E(str3, str, ": could not find Fragment constructor"), e3);
        } catch (InvocationTargetException e4) {
            throw new b(a.E(str3, str, ": calling Fragment constructor caused an exception"), e4);
        }
    }
}
